
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Testtest--管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/ui2/src/css/layui.css" media="all" />
<link rel="stylesheet" href="/ui2/css/public.css" media="all" />

</head>
<body class="childrenBody">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline" style="width: 16%">
    <input type="text" name="id" autocomplete="off" class="layui-input" placeholder="ID"/>
</div><div class="layui-input-inline" style="width: 16%">
    <input type="text" name="tilte" autocomplete="off" class="layui-input" placeholder="文章名"/>
</div><div class="layui-input-inline" style="width: 13%">
    <select title="分类" name="category">
        <option value="">分类</option>
        <option value='0' >历史</option>
<option value='1' >政治</option>
<option value='2' >新闻</option>

    </select>
</div>
<div class="layui-input-inline" style="width: 13%">
    <select title="是否展示" name="switch">
        <option value="">是否展示</option>
        <option value='0' >隐藏</option>
<option value='1' >展示</option>

    </select>
</div>

                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-green  layui-btn-sm search_btn" title="搜索">
                        <i class="layui-icon layui-icon-search "></i>
                    </a>
                    <a class="layui-btn layui-btn-normal layui-btn-sm add_btn layui-hide" title="添加">
                        <i class="layui-icon layui-icon-add-circle"></i>
                    </a>
                    <a class="layui-btn layui-btn-danger layui-btn-sm layui-hide delAll_btn" title="批量删除">
                        <i class="layui-icon layui-icon-delete"></i>
                    </a>
                    <a class="layui-btn layui-btn-sm" title="刷新当前页" href="javascript:void(0);"
                            onclick="layer.load(1);window.location.reload(true);"><i class="layui-icon">&#xe669;</i></a>
                </div>
            </div>
        </form>
    </blockquote>
    <table id="table" lay-filter="table"></table>
    <!--操作-->
    <script type="text/html" id="tool">
        <div class="layui-btn-group">
        <a class="layui-btn layui-btn-sm layui-hide" lay-event="edit" title="编辑">
            <i class="layui-icon layui-icon-edit"></i>
        </a>
        <a class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="del" title="删除">
            <i class="layui-icon layui-icon-delete"></i>
        </a>
        </div>
    </script>
<script type="text/javascript" src="/ui/js/jquery.min.js"></script>

<script type="text/javascript" src="/ui2/src/layui.js"></script>

<script type="text/javascript">
    var tablist = '';
    layui.use(['form', 'layer', 'table', 'laytpl'], function () {
        let form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            laytpl = layui.laytpl,
            table = layui.table;
        //规则列表
        tablist = table.render({
            elem: '#table',
            url: '/ui2/test/1114.json',
            method: 'post',
            page:true,
            limit: 10,
            limits: [10, 20, 50, 100],
            cellMinWidth: 95,
            height: "full-85",
            id: "table",
            cols: [[
                
{field:'id',title:'ID',align:'center',width:80},{field:'tilte',title:'文章名',align:'center'},{field:'addtime',title:'添加时间',align:'center'},{field:'image',title:'头图',align:'center',templet:function(d){
                return '<div><img height="28" src="'+d.image+'"></div>';
            }},{field:'content',title:'内容',align:'center'},{field:'category',title:'分类',align:'center',templet:function(d){
                if(d.category == '0') return '历史';
if(d.category == '1') return '政治';
if(d.category == '2') return '新闻';

            },width:110},{field:'switch',
                title:'是否展示',align:'center',templet:function(d){
                    if('1' === d.switch) return '<div> <span class="layui-badge layui-btn-green">展示</span></div>';
                    if('0' === d.switch) 
                    return '<div><span class="layui-badge">隐藏</span></div>';
                },width:110},

            ]]
        });
        //搜索
        $(".search_btn").on("click", function () {
            tablist.reload({
                where:{
                    para:$('form').serialize()
                }
            });
        });

        //添加
        function addoredit(url,name) {
            let index = layui.layer.open({
                title: name,
                type: 2,
                content: url,
                area:['60%','96%'],
                maxmin:true
            });
            //layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layer.full(index);
            })
        }

        $(".add_btn").on('click',function () {
            addoredit('/admin/Testtest/add','添加');
        });

        //批量删除
        $(".delAll_btn").on('click',function () {
            let checkStatus = table.checkStatus('table'),
                data = checkStatus.data,
                ids = [];
            if (data.length > 0) {
                for (let i in data) {
                    ids.push(data[i].id);
                }
                layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post("/admin/Testtest/delete",{'id':ids},function(data){
                        window.parent.toast(data.info,data.code);
                        if(data.code === 0)
                        tablist.reload();
                    });
                    layer.close(index);
                })
            } else {
                layer.msg("请选择需要删除的数据");
            }
        });

        //列表操作
        table.on('tool(table)', function (obj) {
            let layEvent = obj.event,
                data = obj.data;
            if (layEvent === 'edit') { //编辑
                addoredit('/admin/Testtest/edit/id/'+data.id,'修改');
            } else if (layEvent === 'del') { //删除
                layer.confirm('确定删除这条数据？', {icon: 3, title: '提示'}, function (index) {
                    layer.close(index);
                    $.post("/admin/Testtest/delete",{'id':data.id},function(data){
                        window.parent.toast(data.info,data.code);
                        if(data.code === 0)
                            tablist.reload();
                    });
                });
            }
        });
    })
</script>
</body>
</html>